<?php

namespace app\admin\controller;

use app\common\lib\Param;
use app\common\lib\Show;
use think\response\Json;

class SystemConfig extends AdminBase
{
    public function getData(): Json
    {
        list($type) = Param::getMore([
            ['type',0],
        ], $this->request, true);

        try {
            $systemConfigBis = new \app\common\business\SystemConfig();
            $data=$systemConfigBis->getListByType($type);
            $data =$systemConfigBis->getResetInfo($data);
        }catch (\Exception $e){
            return Show::error([], $e->getMessage(), $e->getCode());
        }
        return Show::success($data);
    }

    public function setData(): Json
    {
        list($website, $email, $phone, $address, $yzcode, $qrcode, $public_name, $public_code, $filing_code, $company) = Param::postMore([
            ['website',''],
            ['email', ''],
            ['phone',''],
            ['address', ''],
            ['yzcode',''],
            ['qrcode', ''],
            ['public_name',''],
            ['public_code', ''],
            ['filing_code',''],
            ['company', ''],
        ], $this->request, true);

        $data=[
            'website'=>$website,
            'email'=>$email,
            'phone'=>$phone,
            'address'=>$address,
            'yzcode'=>$yzcode,
            'qrcode'=>$qrcode,
            'public_name'=>$public_name,
            'public_code'=>$public_code,
            'filing_code'=>$filing_code,
            'company'=>$company,
        ];
        try {
            $result = (new \app\common\business\SystemConfig())->save($data);
        } catch (\Exception $e) {
            return Show::error([], $e->getMessage(), $e->getCode());
        }
        if ($result) {
            return Show::success([], "保存成功");
        }
        return Show::error([], '保存失败');
    }
}
